<?php
class Lib_SMS_Adapter_Chuanglan extends Lib_SMS_Base_Abstract
{
    public static $error_message = [];

    /**
     * 发送短信
     * @param $mobile
     * @param $content
     * @return array|bool
     */
    public function sendCode($mobile, $content){}
    /**
     * 发送短信
     * @param $mobile
     * @param $content
     * @return array|bool
     */
    public function sendSMS($mobile, $content, $sign='')
    {
        // TODO: Implement sendCode() method.
        $phone = implode(",",$mobile);
        //创蓝接口参数
        $post_data = array (
            'account'  =>  $this->config['accounts']['account'],
            'password' => $this->config['accounts']['password'],
            'msg' => $sign.$content,
            'phone' => $phone,
            'report' => true,
        );
        Func_Log::write('SMS', "Chuanglan_Request",  $phone . '|' . json_encode($post_data));
        //接口发送
        $resData = $this->curlPost($this->config['accounts']['url'], $post_data);

        //发送超时，返回错误码
        if ($resData === self::TIME_OUT) {
            Func_Log::write('SMS', "Chuanglan_Response",  $phone . '|' . json_encode($resData));
            return array('code' => 28, 'error' => '请求超时');
        }

        Func_Log::write('SMS', "Chuanglan_Response",  $phone .'|'.$this->config['accounts']['url']. '|' . ($resData));
        $resDataArr = json_decode($resData,true);
        if ($resDataArr['code']=="0") {
            return array('code' => 200, 'message' => $resDataArr['errorMsg'],'data'=>['unique_code'=>$resDataArr['msgId']]);
        } else {
            return array('code' => 400, 'message' => $resDataArr['errorMsg']);
        }
    }



    /**
     * 查询发送状态
     * @param $mobile
     * @param $content
     * @return array|bool
     */
    public function statusQuery()
    {
        // TODO: Implement sendCode() method.
        $appkey=$this->config['accounts']['appkey'];
        $appcode=$this->config['accounts']['appcode'];
        $appsecret=$this->config['accounts']['appsecret'];
        $timestamp=time()."000";

        $post_data = array();
        $post_data['appkey'] = $appkey;
        $post_data['appcode'] = $appcode;
        $post_data['sign'] = md5($appkey.$appsecret.$timestamp);;
        $post_data['timestamp'] = $timestamp;
        $post_data['number'] = 10;

        Func_Log::write('SMS', "Chuanglan_Request",   'statusQuery,$post_data | ' . json_encode($post_data));

        //接口发送
        $resData = $this->curlPost($this->config['accounts']['get_status_url'], $post_data);
        Func_Log::write('SMS', "Chuanglan_Response",  'statusQuery,$post_data |'.$this->config['accounts']['get_status_url']. '|' . $resData);
        return json_decode($resData,true);
    }

}